#include "stdio.h"
#include "SDL/SDL.h"

int main(int argc, char *argv[]) {
	SDL_Surface *screen;	//This pointer will reference the backbuffer
	SDL_Surface *image,*cercle,*croix;	//This pointer will reference our bitmap sprite
	SDL_Surface *temp,*temp2;//This pointer will temporarily reference our bitmap 	sprite
	SDL_Rect src,dest,dest1,dest2,dest3,dest4,dest5,dest6,dest7,dest8,dest9;
	//We must first initialize the SDL video component, and check for success
	SDL_Event event;
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		printf("Unable to initialize SDL: %s\n", SDL_GetError());
		return 1;
	}

	//Set the video mode to fullscreen 640x480 with 16bit colour and double-	buffering
	screen = SDL_SetVideoMode(704, 704, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
	if (screen == NULL) {
		printf("Unable to set video mode: %s\n", SDL_GetError());
		return 1;

	}

	//Load the bitmap into a temporary surface, and check for success
	temp = SDL_LoadBMP("img/image.bmp");
	if (temp == NULL) {
		printf("Unable to load bitmap: %s\n", SDL_GetError());
		return 1;
	}
	//Load the bitmap into a temporary surface, and check for success
	temp2 = SDL_LoadBMP("img/cercle.bmp");
	if (temp2 == NULL) {
		printf("Unable to load bitmap: %s\n", SDL_GetError());
		return 1;
	}
//Load the bitmap into a temporary surface, and check for success
//Convert the surface to the appropriate display format
image = SDL_DisplayFormat(temp);
cercle  = SDL_DisplayFormat(temp2);
//Release the temporary surface
SDL_FreeSurface(temp);
 SDL_FreeSurface(temp2);
//Construct the source rectangle for our blit
	src.x = 0;
	src.y = 0;
	src.w = image->w;	//Use image->w to display the entire width of the image
	src.h = image->h;	//Use image->h to display the entire height of the image
//Construct the destination rectangle for our blit
	dest.x = 0;//Display the image at the (X,Y) coordinates (100,100)
	dest.y = 0;
	dest.w = image->w;
	dest.h = image->h;
int done = 1;

while(done)
{

SDL_BlitSurface(image, &src, screen, &dest);
SDL_BlitSurface(cercle, &src, screen, &dest1);
SDL_BlitSurface(cercle, &src, screen, &dest2);
SDL_BlitSurface(cercle, &src, screen, &dest3);
SDL_BlitSurface(cercle, &src, screen, &dest4);
SDL_BlitSurface(cercle, &src, screen, &dest5);
SDL_BlitSurface(cercle, &src, screen, &dest6);
SDL_BlitSurface(cercle, &src, screen, &dest7);
SDL_BlitSurface(cercle, &src, screen, &dest8);
SDL_BlitSurface(cercle, &src, screen, &dest9);
	//Flip the backbuffer to the primary Hardware Video Memory
	SDL_Flip(screen);

while (SDL_PollEvent(&event))
{
	// check for messages
	switch (event.type)
	{case SDL_KEYDOWN:
		{
			// exit if ESCAPE is pressed

			if (event.key.keysym.sym == SDLK_ESCAPE)
        {done = 0;}
			if (event.key.keysym.sym == SDLK_1)
        {

        dest1.x = 30;//Display the image at the (X,Y) coordinates (100,100)
        dest1.y = 60;
        dest1.w = cercle->w;
        dest1.h = cercle->h;
        }
            if (event.key.keysym.sym == SDLK_2)
        {
        dest2.x = 264;//Display the image at the (X,Y) coordinates (100,100)
        dest2.y = 60;
        dest2.w = cercle->w;
        dest2.h = cercle->h;

	}
             if (event.key.keysym.sym == SDLK_3)
        {
        dest3.x = 498;//Display the image at the (X,Y) coordinates (100,100)
        dest3.y = 60;
        dest3.w = cercle->w;
        dest3.h = cercle->h;
 }
            if (event.key.keysym.sym == SDLK_4)
        {
        dest4.x = 30;//Display the image at the (X,Y) coordinates (100,100)
        dest4.y = 294;
        dest4.w = cercle->w;
        dest4.h = cercle->h;}
            if (event.key.keysym.sym == SDLK_5)
        {

        dest5.x = 264;//Display the image at the (X,Y) coordinates (100,100)
        dest5.y = 294;
        dest5.w = cercle->w;
        dest5.h = cercle->h;}
            if (event.key.keysym.sym == SDLK_6)
        {
        dest6.x = 498;//Display the image at the (X,Y) coordinates (100,100)
        dest6.y = 294;
        dest6.w = cercle->w;
        dest6.h = cercle->h;}
           if (event.key.keysym.sym == SDLK_7)
        {
        dest7.x = 30;//Display the image at the (X,Y) coordinates (100,100)
        dest7.y = 529;
        dest7.w = cercle->w;
        dest7.h = cercle->h;}
            if (event.key.keysym.sym == SDLK_8)
        {
        dest8.x = 264;//Display the image at the (X,Y) coordinates (100,100)
        dest8.y = 529;
        dest8.w = cercle->w;
        dest8.h = cercle->h;
      	SDL_BlitSurface(cercle, &src, screen, &dest8); }
            if (event.key.keysym.sym == SDLK_9)
        {   temp2 = SDL_LoadBMP("img/cercle.bmp");
         cercle  = SDL_DisplayFormat(temp2);
         SDL_FreeSurface(temp2);
        dest9.x = 498;//Display the image at the (X,Y) coordinates (100,100)
        dest9.y = 529;
        dest9.w = cercle->w;
        dest9.h = cercle->h;
SDL_BlitSurface(cercle, &src, screen, &dest9);


        }





		break;

		}
	} // end switch
} // end of message processing


}

SDL_FreeSurface(image);
	return 0; //Return success!
}
